<?php

namespace app\home\controller;

use Composer\Autoload\ClassLoader;
use think\cache\driver\Redis;
use think\Controller;
use think\Request;


class Show extends Controller
{
    public function show(Request $request)
    {
//        查询信息
        $word = input('word');
        $data = \app\home\model\Show::index($word);
        $data = collection($data)->toArray();
        print_r($data);die;
//      设置redis
        $redis = new Redis();

        if ($redis->has('orderData')) {
            echo 'redis';
            $redis->get('orderData');
        } else {
            $data = \app\home\model\Show::index();
            echo 'mysql';
            $redis->set('orderData', $data);
        }
        $this->assign('data', $data);
        return view();
    }

    public function unclear()
    {
        $redis = new Redis();
        $data = $redis->get('orderData');
        $m1 = memory_get_usage();
        unset($data);
        $redis->clear();
        $m2 = memory_get_usage();
        $m = $m1 - $m2;
        return json(['code' => 200, 'msg' => '清除成功,返回结果为' . $m]);
    }
}
